<html>
<head>
    <title>摄像头档案</title>
    <link rel="stylesheet" href="../../../assets/theme-chalk/index.css">
    <link rel="stylesheet" href="../../../style.css">
    <style>
        body {
            background: #F2F2F2;
        }

        .main-head {
            background: #fff;
            padding-left: 10px;
            padding-top: 10px;
            margin-bottom: 0px;
            border: solid 1px #fff;
        }

        .chart-outer {
            height: 200px;
        }


    </style>
</head>
<body>
<div class="page" id="page-elesafe">

    <div class="page-title">设备管理 › 摄像头档案</div>
    <div class="page-main">
        <el-row>
            <el-col :span="24">
                <div class="main-head">
                    <el-form :inline="true">
                        <el-form-item label="">
                            <el-input v-model="CaptorName" placeholder="请输入设备名称关键字" style="width: 220px"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="search" style="background: #578BBB">查询</el-button>
                            <el-button type="primary" @click="addClick" style="background: #5BBD8B">新增</el-button>
                        </el-form-item>
                    </el-form>
                </div>

                <el-table border stripe style="width: 100%" :data="videoData">
                    <el-table-column prop="CaptorName" label="设备名称" align="center">
                    </el-table-column>
                    <el-table-column prop="zone_name" label="安装地址" align="center">
                    </el-table-column>
                    <el-table-column prop="time" label="安装时间" align="center">
                    </el-table-column>
                    <el-table-column label="操作" align="center" fixed="right">
                        <template slot-scope="scope">
                            <el-button @click="handleClick(scope.row)" round size="small"
                                       icon="el-icon-edit"></el-button>
                            <el-button round icon="el-icon-delete" size="small"
                                       @click="delClick(scope.row)"></el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="page-footer" style="left:auto">
                    <el-pagination background layout="prev, pager, next" :pagesize="pagesize" :total="totalCount"
                                   :current-page.sync="pageno" @current-change="onChangePage">
                    </el-pagination>
                </div>


            </el-col>
        </el-row>
        <el-dialog :title="editMod?'编辑摄像头':'新增摄像头'" :visible.sync="dialogFormVisible" center width="25%"
                   :show-close="false">
            <el-form :model="form" ref="form">

                <el-form-item label="设备名称" prop="CaptorName" :label-width="formLabelWidth" :rules="[
                             {required:true,message:'名称不能为空!',trigger:'blur'}
                            ]">
                    <el-input v-model="form.CaptorName" autocomplete="off"></el-input>
                </el-form-item>

                <el-form-item label="安装时间" prop="time" :label-width="formLabelWidth" :rules="[
                             {required:true,message:'安装时间不能为空!',trigger:'blur'}]">
                    <el-date-picker type="datetime" value-format="yyyy-MM-dd HH:mm:ss" v-model="form.time"
                                    placeholder="日期" suffix-icon="el-icon-date" style="width: 100%;"></el-date-picker>
                </el-form-item>
                <el-form-item label="安装地址" prop="ZoneID" :label-width="formLabelWidth">
                    <el-select v-model="form.ZoneID" placeholder="请选择区域">
                        <el-option
                                v-for="item in zoneList"
                                :key="item.zone_id"
                                :label="item.zone_name"
                                :value="item.zone_id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="接入方式" prop="State" :label-width="formLabelWidth" :rules="[
                             {required:true,message:'接入方式不能为空!',trigger:'blur'}
                            ]">
                    <el-select v-model="form.State" placeholder="请选择接入方式" @change="handle_select">
                        <el-option
                                v-for="item in StateList"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="设备ID"  :label-width="formLabelWidth"  prop="videoNo" v-if="form.State==2||form.State == 3">
                    <el-input v-model="form.videoNo" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="设备编码" prop="设备编码" :label-width="formLabelWidth"  v-if="form.State==2">
                    <el-input v-model="form.Url1" autocomplete="off" ></el-input>
                </el-form-item>
                <el-form-item label="视频序列" prop="视频序列" :label-width="formLabelWidth" v-if="form.State==3">
                    <el-input v-model="form.Url2" autocomplete="off" ></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelClick('form')" type="info">取 消</el-button>
                <el-button @click="submitClick('form')" type="success">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</div>


<script type='text/javascript' src='../../../assets/bundle.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../assets/jquery-1.11.2.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../assets/echarts.min.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../js/common.js' charset='utf-8'></script>
<script type='text/javascript' src='../../../js/component.js' charset='utf-8'></script>


<script>

    var vuePage = new Vue({
        el: '#page-elesafe',
        data: {
            formLabelWidth: '120px',
            day: '',
            videoData: '',
            dialogFormVisible: false,
            currentPage: 1,
            form: {},
            editMod: false,
            zoneList: '',
            proList: '',
            CaptorName: '',
            proNo: '',
            zoneId: '',
            pagesize: 10,
            pageno: 1,
            StateList:[
                {value:0,label:'NVR接入'},{value:1,label:'萤石云接入'},{value:2,label:'GBS接入'},{value:3,label:'HIK接入'},
            ],
            totalCount: 0,
        },
        methods: {
            search: function () {
                this.getVideo();
            },
            addClick: function () {
                this.form = {};
                this.editMod = false;
                this.dialogFormVisible = true;
            },
            userNode(data) {

            },
            handleClick(data) {
                console.log(data);
                this.editMod = true;
                this.dialogFormVisible = true;
                // this.form = data;
                this.form = Object.assign(this.form, data);
            },
            delClick(data) {
                this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    HttpUtil.get('VideoCaptor/delete', {Id: data.Id}).success((res) => {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.getVideo();
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            submitClick(formName) {
                this.form.projectNo = SiteConfig.account.projectNo;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if (this.editMod) {
                            HttpUtil.get('VideoCaptor/update', this.form).success((res) => {
                                this.getVideo();
                                this.cancelClick(formName);
                                this.$message({
                                    type: 'success',
                                    message: '修改成功'
                                })
                            })
                        } else {
                            if (this.form.State == 2){
                                if (!this.form.videoNo){
                                    this.$message.warning('设备编码不能为空');
                                    return;
                                }
                            }
                            HttpUtil.get('VideoCaptor/AddVideo', this.form).success((res) => {
                                this.getVideo();
                                this.cancelClick(formName);
                                this.$message({
                                    type: 'success',
                                    message: '保存成功'
                                })
                            })
                        }

                    } else {
                        this.$message({
                            type: 'error',
                            message: '输入内容不能为空'
                        })
                    }

                });

            },
            onChangePage(page) {
                this.pageno = page;
                this.getVideo();
            },
            cancelClick(formName) {
                this.$refs[formName].clearValidate()
                this.dialogFormVisible = false;
            },
            handle_select(val){

            },
            getVideo() {
                var param = {};
                if (this.CaptorName)
                    param.CaptorName = this.CaptorName;
                if (SiteConfig.account.projectNo)
                    param.projectNo = SiteConfig.account.projectNo;
                param.pageno = this.pageno;
                param.pagesize = this.pagesize;
                HttpUtil.get('VideoCaptor/list', param).success((res) => {
                    this.videoData = res.data;
                    vuePage.totalCount = res.total;
                });
            },
        },
        created: function () {
            $('.page').show();
            this.day = TimeUtil.convertToString(new Date()).substr(0, 10);
            this.getVideo();
            HttpUtil.get('Zone/ListForProjectNo', {ProjectNo: SiteConfig.account.projectNo}).success((res) => {
                this.zoneList = res.data;
            });
        },
        mounted: function () {

        }
    });


</script>

</body>
</html>
